import java.util.HashSet;

/**
 * @version Create on 2012-11-2
 * @author Yinzi Chen
 */

public class LongestSubstringWithoutRepeating {

	public int lengthOfLongestSubstring(String s) {
		int n = s.length();
		if (n == 0)
			return 0;
		int max = 1;
		HashSet<Character> set = new HashSet<Character>();
		int l = 0;
		set.add(s.charAt(0));
		for (int i = 1; i < n; ++i) {
			if (!set.contains(s.charAt(i))) {
				set.add(s.charAt(i));
				max = Math.max(max, i - l + 1);
			} else {
				while (s.charAt(l) != s.charAt(i)) {
					set.remove(s.charAt(l));
					l++;
				}
				l++;
			}
		}
		return max;
	}

	public static void main(String[] args) {
		LongestSubstringWithoutRepeating a = new LongestSubstringWithoutRepeating();
		System.out.println(a.lengthOfLongestSubstring("acaccc"));
	}

}
